home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / Information / CSMP Digest / volume 1 / csmp-v1-167.txt < prev    next >
Encoding:
Text File  |  1994-12-08  |  46.0 KB  |  1,230 lines  |  [TEXT/R*ch]

  1. C.S.M.P. Digest             Thu, 13 Aug 92       Volume 1 : Issue 167
  2.  
  3. Today's Topics:
  4.  
  5.     GetKeys() question...
  6.     Is there an Ada Compiler for the Mac ?
  7.     Making the picFrame meaningfull!
  8.     Possible Bug In Think C 5.0.2 Malloc
  9.     windowKind usage
  10.  
  11.  
  12.  
  13. The Comp.Sys.Mac.Programmer Digest is moderated by Michael A. Kelly.
  14.  
  15. The digest is a collection of article threads from the internet newsgroup
  16. comp.sys.mac.programmer.  It is designed for people who read c.s.m.p. semi-
  17. regularly and want an archive of the discussions.  If you don't know what a
  18. newsgroup is, you probably don't have access to it.  Ask your systems
  19. administrator(s) for details.  (This means you can't post questions to the
  20. digest.)
  21.  
  22. Each issue of the digest contains one or more sets of articles (called
  23. threads), with each set corresponding to a 'discussion' of a particular
  24. subject.  The articles are not edited; all articles included in this digest
  25. are in their original posted form (as received by our news server at
  26. cs.uoregon.edu).  Article threads are not added to the digest until the last
  27. article added to the thread is at least one month old (this is to ensure that
  28. the thread is dead before adding it to the digest).  Article threads that
  29. consist of only one message are generally not included in the digest.
  30.  
  31. The entire digest is available for anonymous ftp from ftp.cs.uoregon.edu
  32. [128.223.8.8] in the directory /pub/mac/csmp-digest.  Be sure to read the
  33. file /pub/mac/csmp-digest/README before downloading any files.  The most
  34. recent issues are available from sumex-aim.stanford.edu [36.44.0.6] in the
  35. directory /info-mac/digest/csmp.  If you don't have ftp capability, the sumex
  36. archive has a mail server; send a message with the text '$MACarch help' (no
  37. quotes) to LISTSERV@ricevm1.rice.edu for more information.
  38.  
  39. The digest is also available via email.  Just send a note saying that you
  40. want to be on the digest mailing list to mkelly@cs.uoregon.edu, and you will
  41. automatically receive each new issue as it is created.  Sorry, back issues
  42. are not available through the mailing list.
  43.  
  44. Send administrative mail to mkelly@cs.uoregon.edu.
  45.  
  46.  
  47. -------------------------------------------------------
  48.  
  49. From: fonion@ics.uci.edu
  50. Subject: GetKeys() question...
  51. Date: 6 Jul 92 18:40:58 GMT
  52.  
  53. Hi there,
  54.  
  55.     I need to retrieve keyboard input without using the standard
  56. event mechanisms.  The routine to do this looks like it should be
  57. GetKeys(), but I can't find a way to translate the result of GetKeys()
  58. (a KeyMap) into the corresponding ASCII character.  KeyTrans() will do
  59. this for a virtual key code, but the result of GetKeys() doesn't seem
  60. to correspond with the virtual key codes.  IM I says that the index
  61. into the KeyMap array will be the key code, but I have not found this
  62. to be true.  For example, when I hit the 'j' key, the 0x21 bit of the
  63. KeyMap array is set, but the virtual key code for 'j' is supposed to
  64. be 0x26.
  65.     So, my question is, can GetKeys() be used for this purpose,
  66. and if so, how can the translation into ASCII be done?  If not, is
  67. there an alternative method?  I have checked TN 160 and 263, as well
  68. as IM I, V, and VI to no avail.
  69.     Let me also explain why I am trying to do this, in case anyone
  70. has an alternative solution.  Basically, I need an immediate response
  71. to any keyboard input.  It's not the overhead of using the event
  72. mechanisms that I am worried about, so much as the behavior of the
  73. keyboard through the event mechanisms.  For example, I want to know
  74. whether a key is depressed or not on every iteration, and not have the
  75. delay and repeat restrictions enforced by the event manager.
  76.  
  77.     Either post or email is fine.
  78.  
  79.         Thanks in advance,
  80.             Fritz
  81.             (fonion@ics.uci.edu)
  82.  
  83. +++++++++++++++++++++++++++
  84.  
  85. From: keith@taligent.com (Keith Rollin)
  86. Date: 7 Jul 92 19:19:39 GMT
  87. Organization: Taligent
  88.  
  89. In article <9207061140.aa07315@Paris.ics.uci.edu>, fonion@ics.uci.edu writes:
  90. > Hi there,
  91. >     I need to retrieve keyboard input without using the standard
  92. > event mechanisms.  The routine to do this looks like it should be
  93. > GetKeys(), but I can't find a way to translate the result of GetKeys()
  94. > (a KeyMap) into the corresponding ASCII character.  KeyTrans() will do
  95. > this for a virtual key code, but the result of GetKeys() doesn't seem
  96. > to correspond with the virtual key codes.  IM I says that the index
  97. > into the KeyMap array will be the key code, but I have not found this
  98. > to be true.  For example, when I hit the 'j' key, the 0x21 bit of the
  99. > KeyMap array is set, but the virtual key code for 'j' is supposed to
  100. > be 0x26.
  101. >     So, my question is, can GetKeys() be used for this purpose,
  102. > and if so, how can the translation into ASCII be done?  If not, is
  103. > there an alternative method?  I have checked TN 160 and 263, as well
  104. > as IM I, V, and VI to no avail.
  105. >     Let me also explain why I am trying to do this, in case anyone
  106. > has an alternative solution.  Basically, I need an immediate response
  107. > to any keyboard input.  It's not the overhead of using the event
  108. > mechanisms that I am worried about, so much as the behavior of the
  109. > keyboard through the event mechanisms.  For example, I want to know
  110. > whether a key is depressed or not on every iteration, and not have the
  111. > delay and repeat restrictions enforced by the event manager.
  112.  
  113. It sounds to me like you are having problems determining which way to count.
  114. Don't worry, I have that problem, too.
  115.  
  116. In the keyMap, the first byte covers virtual keycodes 0-7, the second byte
  117. keycodes 8-0x0F, and so on. If you carry this out, you'll see that keycodes 0x21
  118. and 0x26 are in the same byte.
  119.  
  120. The question is: are the bits in the byte numbered from left-to-right or
  121. right-to-left. If you count one way, keycode 0x21 is the second from the right
  122. and keycode 0x26 is second from the left. If you count the other way, then their
  123. positions are swapped. Therefore, its easy to confuse 0x21 with 0x26.
  124.  
  125. I don't bother with it any more. I finally got a routine that worked, and I just
  126. use it. Here it is:
  127.  
  128. Boolean    KeyIsDown(short keyCode)
  129. {
  130.     union {
  131.         KeyMap            asMap;
  132.         unsigned char    asBytes[16];
  133.     } myMap;
  134.  
  135.     GetKeys(myMap.asMap);
  136.     return ((myMap.asBytes[keyCode >> 3] >> (keyCode & 0x07)) & 1) != 0;
  137. }
  138.  
  139.  
  140. To use it, just do something like:
  141.  
  142. Boolean    OptionKeyIsDown()
  143. {
  144.     const short kOptionKey = 0x3A;
  145.  
  146.     return KeyIsDown(kOptionKey);
  147. }
  148.  
  149.  
  150. Hope this helps,
  151.  
  152. - --
  153. Keith Rollin
  154. Phantom Programmer
  155. Taligent, Inc.
  156.  
  157. +++++++++++++++++++++++++++
  158.  
  159. From: gt0657c@prism.gatech.EDU (geoff george)
  160. Date: 11 Jul 92 05:24:30 GMT
  161. Organization: Georgia Institute of Technology
  162.  
  163. Re. Checking the Mac for a keypress,
  164.  
  165. Use EventAvail() if you can; it's lots simpler.
  166.  
  167. Here's the code I wound up having to write to poll the keyboard 
  168. reasonably quickly - EventAvail() turned out to be way too slow. 
  169. This code is based on TechNotes 160 and 263; I took it directly 
  170. out of the program I'm working on, and added a few declarations 
  171. in the first first section so it would compile with no errors 
  172. by itself. The stuff below the second /*  --------<>--------  */ 
  173. is unchanged from my source code. 
  174.  
  175. This seems like an awful lot of code to do something relatively 
  176. simple; if anyone can offer suggestions for improving this code 
  177. or notices bugs, I'd appreciate hearing about it. 
  178.  
  179. To use this code, call InitKeyTransStuff() when your program 
  180. starts up; it returns FALSE if it fails, and TRUE if it succeeds. 
  181. Anytime afterwards, you can call PollKeyDown(), which returns the 
  182. ascii code for a key which is down, or 0 if no key is down. This 
  183. is the same "ascii" code as would have been returned in the low 
  184. byte (charCodeMask) of the message field of an EventRecord. 
  185. (Maybe I should return -1 for "no key.") If more than one key 
  186. is down, I just return the ascii code for the first one I find, 
  187. i.e. the one whose key code is least.
  188.  
  189. InternalError() is a utility routine I use which displays an 
  190. error alert containing the given message, and always returns 
  191. FALSE. (Virtually all of the Boolean routines I write contain 
  192. something like, 
  193.  
  194.     if (error condition)
  195.        return InternalError ("Error condition happened.");
  196.  
  197. MyGetResource() simply calls GetResource, and calls InternalError() 
  198. if any error occurs, then returns the resource handle or NIL as 
  199. appropriate. 
  200.  
  201.  
  202. Hope this helps.
  203.  
  204. geoff
  205. - --
  206. geoff george    geoff@cc.gatech.edu        (my name)
  207.         or    gt0657c@prism.gatech.edu   (personal warmth from GaTech OCS)
  208.  
  209. "Ordinary f---ing people - I hate 'em. Ordinary person spends his life avoiding
  210. tense situations; repo man spends his life getting INTO tense situations."
  211.  
  212.  
  213.  
  214.     /*  --------<>--------  */
  215.  
  216.  
  217.  
  218. #include <Script.h>
  219.  
  220.  
  221.  
  222. #define NIL    ((void *) 0L)
  223.  
  224.  
  225. typedef unsigned long    ulong;
  226. typedef unsigned short    ushort;
  227. typedef unsigned char    uchar;
  228.  
  229.  
  230. Boolean        InternalError (const char * errmsg);
  231. Handle        MyGetResource (ResType rt, short resID, const char * caller);
  232.  
  233. Boolean        InitKeyTransStuff (void);
  234. short        PollKeyDown (void);
  235.  
  236.  
  237.  
  238.     /*  --------<>--------  */
  239.  
  240.  
  241.  
  242.     // some virtual key codes
  243. #define COMMAND_KEY        0x37
  244. #define SHIFT_KEY        0x38
  245. #define CAPS_LOCK_KEY        0x39
  246. #define OPTION_KEY        0x3a
  247. #define CONTROL_KEY        0x3b
  248. #define RIGHT_SHIFT_KEY        0x3c
  249. #define RIGHT_OPTION_KEY    0x3d
  250. #define RIGHT_CONTROL_KEY    0x3e
  251.  
  252.  
  253. #define KEY_BIT(n)    ((((uchar *) km) [n >> 3] & (1 << (n & 7))) != 0)
  254.  
  255.  
  256.  
  257. // Cf. TNs 160, 263. 
  258.  
  259.  
  260. static Handle    kchr = NIL;
  261. static Boolean    isModifierKey [128];
  262.  
  263.  
  264. Boolean        InitKeyTransStuff (void)
  265. {
  266. long        scriptID;
  267. int        i;
  268.  
  269. for (i = 0; i < 128; i++)
  270.    isModifierKey [i] = FALSE;
  271.  
  272. isModifierKey [COMMAND_KEY] = TRUE;
  273. isModifierKey [SHIFT_KEY] = TRUE;
  274. isModifierKey [CAPS_LOCK_KEY] = TRUE;
  275. isModifierKey [OPTION_KEY] = TRUE;
  276. isModifierKey [CONTROL_KEY] = TRUE;
  277. isModifierKey [RIGHT_SHIFT_KEY] = TRUE;
  278. isModifierKey [RIGHT_OPTION_KEY] = TRUE;
  279. isModifierKey [RIGHT_CONTROL_KEY] = TRUE;
  280.  
  281. scriptID = GetScript(GetEnvirons (smKeyScript), smScriptKeys);
  282. kchr = MyGetResource ('KCHR', (short) scriptID, "InitKeyTransStuff()");
  283. if (kchr != NIL && * kchr != NIL)
  284.    HNoPurge (kchr);
  285.  
  286. return kchr != NIL && * kchr != NIL;
  287. }
  288.  
  289.  
  290.  
  291.     // 0 if none
  292. short        PollKeyDown (void)
  293. {
  294. ulong        asciis;
  295. long        ktState = 0L;
  296. ushort        asciiCode, keyCode;
  297. KeyMap        km;
  298.  
  299. if (kchr == NIL || * kchr == NIL)
  300.    {
  301.    InternalError ("Keyboard ascii character man not initialized"
  302.          " in PollKeyDown().");
  303.    return 0;
  304.    }
  305.  
  306. GetKeys (km);
  307. if ((km [0] | km [1] | km [2] | km [3]) == 0)
  308.    return FALSE;
  309.  
  310. for (keyCode = 0; keyCode < 128; keyCode++)
  311.    if (! isModifierKey [keyCode] && KEY_BIT (keyCode))
  312.             break;
  313.  
  314. if (keyCode > 127)
  315.    return 0;
  316.  
  317. if (KEY_BIT (SHIFT_KEY) || KEY_BIT (RIGHT_SHIFT_KEY))
  318.    keyCode |= shiftKey;
  319. if (KEY_BIT (CAPS_LOCK_KEY))
  320.    keyCode |= alphaLock;
  321. if (KEY_BIT (OPTION_KEY) || KEY_BIT (RIGHT_OPTION_KEY))
  322.    keyCode |= optionKey;
  323. if (KEY_BIT (CONTROL_KEY) || KEY_BIT (RIGHT_CONTROL_KEY))
  324.    keyCode |= controlKey;
  325.  
  326. asciis = KeyTrans ((Ptr) * kchr, (short) keyCode, & ktState);
  327. asciiCode = (asciis >> 16) & 0xff;
  328. if (asciiCode == 0)
  329.    asciiCode = asciis & 0xff;
  330.  
  331. return asciiCode;
  332. }
  333.  
  334.  
  335.  
  336. - -- 
  337. geoff george    geoff@cc.gatech.edu        (my name)
  338.         or    gt0657c@prism.gatech.edu   (personal warmth from GaTech OCS)
  339.  
  340. "Ordinary f---ing people - I hate 'em. Ordinary person spends his life avoiding tense situations; repo man spends his life getting INTO tense situations."
  341.  
  342. ---------------------------
  343.  
  344. From: jlim@eeserv.ee.umanitoba.ca (Johnny Lim)
  345. Subject: Is there an Ada Compiler for the Mac ?
  346. Date: 7 Jul 92 23:18:56 GMT
  347. Organization: Electrical Engineering, U of Manitoba, Winnipeg, Manitoba, Canada
  348.  
  349.  
  350. Hi there,
  351.  
  352. Is there any Ada Compiler for the Macintosh ? 
  353. I will appreciate if someone can point out where I can find 
  354. either a public domain or commercial ada compiler for the Mac Plus.
  355.  
  356. Thank you for your time.
  357.  
  358. Johnny Lim
  359. jlim@eeserv.ee.umanitoba.ca
  360.  
  361. +++++++++++++++++++++++++++
  362.  
  363. From: alex@cs.umd.edu (Alex Blakemore)
  364. Date: 8 Jul 92 02:38:43 GMT
  365. Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742
  366.  
  367. In article <1992Jul7.231856.343@ccu.umanitoba.ca> jlim@eeserv.ee.umanitoba.ca (Johnny Lim) writes:
  368. > Is there any Ada Compiler for the Macintosh ? 
  369. > I will appreciate if someone can point out where I can find 
  370. > either a public domain or commercial ada compiler for the Mac Plus.
  371.  
  372. Meridian Software Systems markets an Ada compiler for the Mac.
  373. I believe it is reasonably priced relative to other Ada compilers.
  374. The product name is OpenAda, contact them for more info:
  375.  
  376.     (714)727-0700
  377. FAX (714)727-3583
  378.  
  379. support@meridian.com - tech support I imagine they can connect
  380.                        you with sales.
  381.  
  382. OpenAda is available also on PC, NeXT, Sun and other platforms.
  383. there are related supporting tools in addition to the compiler
  384.  
  385. - -- 
  386. - -------------------------------
  387. Alex Blakemore alex@cs.umd.edu
  388.  
  389. +++++++++++++++++++++++++++
  390.  
  391. From: mfeldman@milton.u.washington.edu (Michael Feldman)
  392. Date: 10 Jul 92 06:22:46 GMT
  393. Organization: University of Washington, Seattle
  394.  
  395. In article <1992Jul7.231856.343@ccu.umanitoba.ca> jlim@eeserv.ee.umanitoba.ca (Johnny Lim) writes:
  396. >
  397. >Hi there,
  398. >
  399. >Is there any Ada Compiler for the Macintosh ? 
  400. >I will appreciate if someone can point out where I can find 
  401. >either a public domain or commercial ada compiler for the Mac Plus.
  402. >
  403. No public-domain one yet (wait till GNAT is ready in 93). Commercial
  404. compilers for MacOS come from Meridian and Alsys (attractive student
  405. prices, by the way); both run under MPW. The Alsys one needs a big
  406. Mac (68020 or 68030 with virtual memory, I think); the Meridian one
  407. doesn't.
  408.  
  409. TeleSoft makes an A/UX compiler.
  410.  
  411. Mike Feldman
  412.  
  413. +++++++++++++++++++++++++++
  414.  
  415. From: ae@sei.cmu.edu (Arthur Evans)
  416. Date: 10 Jul 92 13:10:50 GMT
  417. Organization: Software Engineering Institute
  418.  
  419. jlim@eeserv.ee.umanitoba.ca (Johnny Lim) asked about Ada compilers for
  420. the Mac.
  421.  
  422. mfeldman@milton.u.washington.edu (Michael Feldman) responded with info
  423. about Alsys and Meridian compilers.
  424.  
  425. An additional point: Only the Meridian compiler works under System 7.
  426. The libraries have not been upgraded to have the new System 7 calls (a
  427. minor inconvenience), but the compiler works fine.  I've been using it
  428. successfully for software development.
  429.  
  430. As far as I know, neither vendor plans to upgrade fully for System 7.
  431.  
  432. Art Evans
  433. - ----------------------------------------------
  434. Arthur Evans, Jr, PhD           Ada Consultant
  435. 461 Fairview Road
  436. Pittsburgh PA  15238-1933
  437. 412-963-0839
  438. ae@sei.cmu.edu
  439.  
  440. ---------------------------
  441.  
  442. From: sll2@cunixa.cc.columbia.edu (Steven L Levitt)
  443. Subject: Making the picFrame meaningfull!
  444. Date: 8 Jul 92 04:13:08 GMT
  445. Organization: Columbia University
  446.  
  447. Here's an exercise for all of you to chew over;  How may one coerce a Picture
  448. into drawing only that which would fit in its picFrame?
  449.  
  450. To flesh things out a bit;  I have a sequence of drawing commands I save as a 
  451. Picture.  However, there are times when I want to draw only a part of this 
  452. picture, and, furthermore, there are times when I want to draw this picture
  453. while another picture is being defined, i.e. I want only what I can "see" in 
  454. the first picture to be contained in the second.  Utilizing a clipping region
  455. is no good because all drawing commands are included in a picture definition
  456. regardless of whether they would actually be visible.  So I suppose I am asking
  457. how I may _selectively_ execute the opcodes in a picture definition.
  458.  
  459. Thanks in advance, and $100,000,000,000,000,000,000.01 to the one with the best
  460. response.
  461.  
  462. Naturally, I'm kidding.  Duh.
  463.  
  464. - ----------------
  465. Steven L. Levitt  sll2@cunixa.cc.columbia.edu
  466. An Undergrad
  467.  
  468. +++++++++++++++++++++++++++
  469.  
  470. From: zben@ni.umd.edu (Charles B. Cranston)
  471. Organization: UM Home for the Terminally Analytical
  472. Date: Wed, 8 Jul 1992 20:22:00 GMT
  473.  
  474. In article <1992Jul8.041308.3062@news.columbia.edu>, sll2@cunixa.cc.columbia.edu (Steven L Levitt) writes:
  475.  
  476. > How may one coerce a Picture into drawing only that which would fit in its picFrame?
  477.  > Utilizing a clipping region is no good because all drawing commands are included
  478. > in a picture definition regardless of whether they would actually be visible.
  479.  
  480. I would start by creating a grafport, then patching in my own versions of the
  481. QuickDraw bottleneck routines, then playing the picture into the grafport.
  482. The bottleneck routines would SectRect the rectangle being drawn into with
  483. the rectangle of the grafport and omit calling the real bottlenecks if the
  484. drawing would not be visible.
  485.  
  486. Now, I've never actually tried to do this.  Another programmer of my acquaintance
  487. claims that system bugs prevent you from playing a picture into a grafport that
  488. is simultaniously recording another picture.  Is this true, or is my friend just
  489. being killed by a bug in his own stuff that he cannot find?
  490.  
  491. I didn't see anywhere in Inside Mac that you have to lock a picture before you
  492. play it, but doing so fixed a bug in one of my programs once.  Is this the pooled
  493. experience of the group, or does one of my many INITs patch DrawPicture with
  494. code that allocates memory?
  495.  
  496.  
  497. +++++++++++++++++++++++++++
  498.  
  499. From: oster@well.sf.ca.us (David Phillip Oster)
  500. Organization: Whole Earth 'Lectronic Link
  501. Date: Fri, 10 Jul 1992 06:28:06 GMT
  502.  
  503. In article <1992Jul8.202200.26907@ni.umd.edu> zben@ni.umd.edu (Charles B. Cranston) writes:
  504. _>In article <1992Jul8.041308.3062@news.columbia.edu>, sll2@cunixa.cc.columbia.edu (Steven L Levitt) writes:
  505. _> 
  506. _>> How may one coerce a Picture into drawing only that which would fit in its picFrame?
  507. _>> Utilizing a clipping region is no good because all drawing commands are included
  508. _>> in a picture definition regardless of whether they would actually be visible.
  509. _>I would start by creating a grafport, then patching in my own versions of the
  510. _>QuickDraw bottleneck routines, then playing the picture into the grafport.
  511. _>The bottleneck routines would SectRect the rectangle being drawn into with
  512. _>the rectangle of the grafport and omit calling the real bottlenecks if the
  513. _>drawing would not be visible.
  514. Note, you only need to set the clip at the beginning of the picture, then
  515. override just the clip setting bottleneck procedure, and never pass any
  516. illegally widening clip command into the destination pict. You can leave all
  517. the other bottlenecks alone, since they will all clip against the current
  518. clipRgn.
  519.  
  520. _>Now, I've never actually tried to do this.  Another programmer of my acquaintance
  521. _>claims that system bugs prevent you from playing a picture into a grafport that
  522. _>is simultaniously recording another picture.  Is this true, or is my friend just
  523. _>being killed by a bug in his own stuff that he cannot find?
  524. Not true. You can play oone picture while you are recording another.
  525. _>I didn't see anywhere in Inside Mac that you have to lock a picture before you
  526. _>play it, but doing so fixed a bug in one of my programs once.  Is this the pooled
  527. _>experience of the group, or does one of my many INITs patch DrawPicture with
  528. _>code that allocates memory?
  529.  
  530. Well, you need to make the Pict non-purgeable, but you don't need to lock
  531. it. Of course, if you say something lieke DrawPicture(ph, &(**ph).picFrame);
  532. you deserve to bus error, since the pic can move during playing: suppose it
  533. has to load a font into memory, for example. You should have said:
  534. Rect r;
  535. r = (**ph).picFrame;
  536. DrawPicture(ph, &r);
  537.  
  538.  
  539. ---------------------------
  540.  
  541. From: brian@galileo.jsc.nasa.gov (Brian Donnell)
  542. Subject: Possible Bug In Think C 5.0.2 Malloc
  543. Date: 8 Jul 92 17:55:10 GMT
  544. Organization: NASA/JSC
  545.  
  546. We have a program which does a bunch of little mallocs and
  547. then later frees them (not necessarily in the same order
  548. they were created).  This program eventually runs out of
  549. memory, and I am quite certain there are no memory leaks
  550. in the program.  If I do large mallocs (> than the 15K
  551. crossover size mentioned in the Think C library source),
  552. I do not have this problem.  I think there is a subtle
  553. bug in the Think C alloc.c library file which in
  554. certain scenarios loses memory for a sequence of mallocs
  555. and frees of small blocks.  When the blocks are large
  556. enough and the library uses NewPtr, the problem does not
  557. appear to occur.
  558.  
  559. I was hoping to post a sample program, but I cannot
  560. reproduce it easily.  Symantec folks, are you aware of
  561. a bug of this nature?  If so, when can we expect a fix?
  562.  
  563. Thanks -
  564. Brian Donnell
  565. NASA/JSC
  566.  
  567. +++++++++++++++++++++++++++
  568.  
  569. From: phils@chaos.cs.brandeis.edu (Phil Shapiro)
  570. Organization: Symantec Corp.
  571. Date: Thu, 9 Jul 1992 15:05:39 GMT
  572.  
  573. >>>>> On Wed, 8 Jul 1992 17:55:10 GMT, brian@galileo.jsc.nasa.gov (Brian Donnell) said:
  574.  
  575.  > We have a program which does a bunch of little mallocs and then
  576.  > later frees them (not necessarily in the same order they were
  577.  > created).  This program eventually runs out of memory, and I am
  578.  > quite certain there are no memory leaks in the program.  If I do
  579.  > large mallocs (> than the 15K crossover size mentioned in the Think
  580.  > C library source), I do not have this problem.  I think there is a
  581.  > subtle bug in the Think C alloc.c library file which in certain
  582.  > scenarios loses memory for a sequence of mallocs and frees of small
  583.  > blocks.  When the blocks are large enough and the library uses
  584.  > NewPtr, the problem does not appear to occur.
  585.  
  586.  > I was hoping to post a sample program, but I cannot reproduce it
  587.  > easily.  Symantec folks, are you aware of a bug of this nature?  If
  588.  > so, when can we expect a fix?
  589.  
  590. Well, this isn't really a bug; it's more of a case where our malloc
  591. strategy doesn't produce maximal results. There are a number of ways
  592. to write malloc, and each has its benefits and deficiencies. Our way
  593. is pretty fast at allocating blocks, and extremely fast a freeing
  594. them. On the downside, we don't have any strategy of looking for a
  595. "best fit". Our malloc simply takes the next free block that has
  596. enough room, and this can lead to inefficient use of memory in some
  597. cases.
  598.  
  599. You may want to make a custom version of the ANSI library that
  600. replaces the malloc routines with direct Mac Memory manager calls. The
  601. results are slower but may result in more efficient use of memory.
  602.  
  603.     -phil
  604. - --
  605.    Phil Shapiro                                   Software Engineer
  606.    Language Products Group                     Symantec Corporation
  607.            Internet: phils@cs.brandeis.edu
  608.  
  609. +++++++++++++++++++++++++++
  610.  
  611. From: k044477@hobbes.kzoo.edu (Jamie R. McCarthy)
  612. Organization: Kalamazoo College
  613. Date: Thu, 9 Jul 1992 16:34:08 GMT
  614.  
  615. phils@chaos.cs.brandeis.edu (Phil Shapiro) writes:
  616. >brian@galileo.jsc.nasa.gov (Brian Donnell) said:
  617. >
  618. > > We have a program which does a bunch of little mallocs and then
  619. > > later frees them...
  620. > > This program eventually runs out of memory, and I am
  621. > > quite certain there are no memory leaks in the program.
  622. > > ... I think there is a
  623. > > subtle bug in the Think C alloc.c library file which in certain
  624. > > scenarios loses memory for a sequence of mallocs and frees of small
  625. > > blocks.  When the blocks are large enough and the library uses
  626. > > NewPtr, the problem does not appear to occur.
  627. >
  628. >There are a number of ways
  629. >to write malloc.... Our way
  630. >is pretty fast at allocating blocks, and extremely fast a freeing
  631. >them. On the downside, we don't have any strategy of looking for a
  632. >"best fit". Our malloc simply takes the next free block that has
  633. >enough room, and this can lead to inefficient use of memory in some
  634. >cases.
  635. >
  636. >You may want to make a custom version of the ANSI library that
  637. >replaces the malloc routines with direct Mac Memory manager calls. The
  638. >results are slower but may result in more efficient use of memory.
  639.  
  640. I'm also working on a project that uses malloc(), and for my purposes,
  641. Think's version was completely unacceptable.  From looking at the
  642. source, I believe it's impossible for Think's malloc to ever call
  643. DisposPtr unless you're freeing a block larger than the 15K crossover
  644. size.
  645.  
  646. In some cases, this may cause problems.  Consider calling malloc(98) 150
  647. times.  This will return you 150 98-byte blocks which, together with the
  648. overhead, take up one entire 15000-byte block.  Now free() them all.
  649. Now call malloc(99).  Think's malloc(), since it doesn't accumulate free
  650. space, will have to allocate an entirely new 15000-byte block.
  651.  
  652. Any non-application _must_not_ use Think's malloc().  My first try at my
  653. screensaver left 15K non-relocatable driblets all over the system heap
  654. until I figured out what was going on.  I didn't have the luxury of
  655. trusting _ExitToShell to clean up for me.
  656.  
  657. Eric Sink suggested using Tim Endres' (time@ice.com) malloc, which he
  658. calls "icemalloc".  I had to hack it up to get it to compile, because
  659. the version I found was pre-ANSI, but it works wonderfully.  It does
  660. reaccumulate free space, is fast, has a maximum block size of 16 megs,
  661. and has other features besides.  (Because Tim lets you dispose of a
  662. "pool" of allocations at once, I can free everything at once, much
  663. quicker than Think's "extremely fast" free().)
  664.  
  665. That said, I can't remember where I ftp'd icemalloc from.  (blush)
  666.  
  667. (This isn't a slam on Symantec, I still love Think C!)
  668. - -- 
  669.  Jamie McCarthy      Internet: k044477@kzoo.edu      AppleLink: j.mccarthy
  670.  I suppose ya don't think I was run over by a streetcar!
  671.  
  672. +++++++++++++++++++++++++++
  673.  
  674. From: jstevens@crick.ssctr.bcm.tmc.edu (Jason Philip Stevens)
  675. Date: 9 Jul 1992 16:53:11 GMT
  676. Organization: Baylor College of Medicine, Houston, Tx
  677.  
  678.  
  679. |> Eric Sink suggested using Tim Endres' (time@ice.com) malloc, which he
  680. |> calls "icemalloc".  I had to hack it up to get it to compile, because
  681. |> the version I found was pre-ANSI, but it works wonderfully.  It does
  682. |> reaccumulate free space, is fast, has a maximum block size of 16 megs,
  683. |> and has other features besides.  (Because Tim lets you dispose of a
  684. |> "pool" of allocations at once, I can free everything at once, much
  685. |> quicker than Think's "extremely fast" free().)
  686. |> 
  687. |> That said, I can't remember where I ftp'd icemalloc from.  (blush)
  688.  
  689. If anyone knows where this is, could you please post an ftp site?  Alternately,
  690. Jamie, could you publish your hacked copy?  Thanks.
  691.  
  692. - -jps
  693. - -- 
  694. Jason Stevens            Internet:  jstevens@bcm.tmc.edu
  695. Network User Services        Voice:  (713) 798-7370
  696. Baylor College of Medicine    Opinions expressed are mine alone.
  697.  
  698.  
  699. +++++++++++++++++++++++++++
  700.  
  701. From: k044477@hobbes.kzoo.edu (Jamie R. McCarthy)
  702. Organization: Kalamazoo College
  703. Date: Thu, 9 Jul 1992 18:11:34 GMT
  704.  
  705. jstevens@crick.ssctr.bcm.tmc.edu (Jason Philip Stevens) writes:
  706. >[Jamie writes:]
  707. >|> Eric Sink suggested using Tim Endres' (time@ice.com) malloc, which he
  708. >|> calls "icemalloc".  I had to hack it up to get it to compile...
  709. >
  710. >Jamie, could you publish your hacked copy?  Thanks.
  711.  
  712. I emailed Tim and asked him for permission to publish both his and my
  713. source together when the module's done;  if he agrees, I'll let y'all
  714. know when I'm done.  (I hope that 5-year-old address is valid;  it
  715. hasn't bounced since I wrote it an hour ago, but nslookup couldn't find
  716. ice.com.  Hmmmm.)
  717. - -- 
  718.  Jamie McCarthy      Internet: k044477@kzoo.edu      AppleLink: j.mccarthy
  719.  When the ship runs out of water and the vessel runs aground, land's where we
  720.  know the boat is found.  Now, there's nothing unexpected about the water
  721.  giving out;  "land"'s not a word we have to shout.  -- TMBG, "Women and Men"
  722.  
  723. +++++++++++++++++++++++++++
  724.  
  725. From: kevin@crash.cts.com (Kevin Hill)
  726. Date: 9 Jul 92 17:00:31 GMT
  727. Organization: Crash TimeSharing, El Cajon, CA
  728.  
  729. In <1992Jul8.175510.15997@aio.jsc.nasa.gov> brian@galileo.jsc.nasa.gov (Brian Donnell) writes:
  730.  
  731. >We have a program which does a bunch of little mallocs and
  732. >then later frees them (not necessarily in the same order
  733. >they were created).  This program eventually runs out of
  734. >memory, and I am quite certain there are no memory leaks
  735. >in the program.  If I do large mallocs (> than the 15K
  736. >crossover size mentioned in the Think C library source),
  737. >I do not have this problem.  I think there is a subtle
  738. >bug in the Think C alloc.c library file which in
  739. >certain scenarios loses memory for a sequence of mallocs
  740. >and frees of small blocks.  When the blocks are large
  741. >enough and the library uses NewPtr, the problem does not
  742. >appear to occur.
  743.  
  744. >I was hoping to post a sample program, but I cannot
  745. >reproduce it easily.  Symantec folks, are you aware of
  746. >a bug of this nature?  If so, when can we expect a fix?
  747.  
  748. >Thanks -
  749. >Brian Donnell
  750. >NASA/JSC
  751.  
  752. j  How large is a large number of mallocs?  If it is really large, then perhaps
  753. the bug lies in the fact that malloc does not return the memory for the 
  754. information about its memory allocations. (this is just guessing though.)
  755.  
  756.   Why don't you just use NewPtr and NewHandle for ANY memory allocations,
  757. they are able to handle any type of memory allocation that you could want...
  758.  
  759.  -Kevin Hill
  760.  
  761. +++++++++++++++++++++++++++
  762.  
  763. From: d88-jwa@cyklop.nada.kth.se (Jon W{tte)
  764. Date: 9 Jul 92 23:07:41 GMT
  765. Organization: Royal Institute of Technology, Stockholm, Sweden
  766.  
  767. > k044477@hobbes.kzoo.edu (Jamie R. McCarthy) writes:
  768.  
  769.    Any non-application _must_not_ use Think's malloc().  My first try at my
  770.    screensaver left 15K non-relocatable driblets all over the system heap
  771.    until I figured out what was going on.  I didn't have the luxury of
  772.    trusting _ExitToShell to clean up for me.
  773.  
  774. Hey, NOTHING RELEASED on the mac should call malloc().
  775. Or anything in the ANSI library. The mac is the mac is the mac,
  776. it has a toolbox, and you'd better use it. The C library
  777. functions, ... well, they WORK, for porting apps in your own
  778. spare time, but they're not suited to programming the mac way.
  779.  
  780. - -- 
  781.          Jon W{tte, Svartmangatan 18, S-111 29 Stockholm, Sweden
  782.  
  783. ### You have the Easy Access virus. This virus may cause strange sounds
  784. ### and weird keyboard behaviour when you press the shift key repeatedly.
  785.  
  786. +++++++++++++++++++++++++++
  787.  
  788. From: k044477@hobbes.kzoo.edu (Jamie R. McCarthy)
  789. Organization: Kalamazoo College
  790. Date: Fri, 10 Jul 1992 04:06:05 GMT
  791.  
  792. d88-jwa@cyklop.nada.kth.se (Jon W{tte) writes:
  793. >> k044477@hobbes.kzoo.edu (Jamie R. McCarthy) writes:
  794. >
  795. >   Any non-application _must_not_ use Think's malloc().
  796. >
  797. >Hey, NOTHING RELEASED on the mac should call malloc().
  798. >... The mac is the mac is the mac,
  799. >it has a toolbox, and you'd better use it.
  800.  
  801. Er, Jon...
  802.  
  803. The best algorithm for what I'm doing requires that I allocate, as near
  804. as I can figure, about 2000 20-byte blocks.  NewPtr() just won't cut it,
  805. the Memory Manager isn't designed for that.
  806.  
  807. I have to put some kind of middle ground between me and the toolbox;
  808. even if I write it myself and call it MonstrousMacMemoryManager(), it
  809. still does the same thing as the ANSI function malloc().  Why shouldn't
  810. I save myself the work and borrow someone else's (gasp) ANSI code?
  811. - -- 
  812.  Jamie McCarthy      Internet: k044477@kzoo.edu      AppleLink: j.mccarthy
  813.  If I see one more goddam signature virus, I'm gonna scream.
  814.  
  815. +++++++++++++++++++++++++++
  816.  
  817. From: d88-jwa@dront.nada.kth.se (Jon W{tte)
  818. Organization: Royal Institute of Technology, Stockholm, Sweden
  819. Date: Fri, 10 Jul 1992 09:25:50 GMT
  820.  
  821. > k044477@hobbes.kzoo.edu (Jamie R. McCarthy) writes:
  822.  
  823.    >Hey, NOTHING RELEASED on the mac should call malloc().
  824.    >... The mac is the mac is the mac,
  825.    >it has a toolbox, and you'd better use it.
  826.  
  827.    The best algorithm for what I'm doing requires that I allocate, as near
  828.    as I can figure, about 2000 20-byte blocks.  NewPtr() just won't cut it,
  829.    the Memory Manager isn't designed for that.
  830.  
  831. Ah, but you KNOW you allocate 20-byte blocks ? How about this:
  832.  
  833. A function NewBlock that gives you a pointer to a 20-byte block,
  834. and DisposeBlock that marks one as free. Implemented by pools
  835. of 500 blocks, with a 2-byte overhead per block (free list) + 2
  836. bytes per pool for allocation count; when allocation count reaches
  837. 0 you release the entire pool. If you want faster frees, you
  838. can add 2 (or 4) bytes per block for an offset/pointer to the pool
  839. start for each block.
  840.  
  841. NewBlock:
  842.     Check the list of non-empty pools.
  843.     If not empty:
  844.         If full:
  845.             Move to list of full pools.
  846.     Else:
  847.         Create new pool.
  848.         Get the next free block.
  849.         Mark as used, remove from free list.
  850.         Decrease free count
  851.     Return block thus found
  852.  
  853. FreeBlock:
  854.     (optional sanity-checking of pointer)
  855.     Find pool the block belongs to.
  856.     If pool is in full pool list:
  857.         Move to not-full pool list.
  858.     Mark block as free, insert in free list for pool.
  859.     Increase free count.
  860.     If completely empty:
  861.         Release pool.
  862.         Remove from non-empty pool list.
  863.  
  864. Can easily be generalized to a variable-sized malloc
  865. (with different pools for different powers of 2 sizes
  866. for instance) and to perform allocation in specific
  867. pools (so you can give an entire pool up)
  868.  
  869. Should be easy to implement, and FAR faster than Think Cs malloc.
  870. (The pseudo-code is off the top of my head; I haven't really
  871. studied the area of efficient memory allocation schemes in-depth,
  872. but this seems like a clean, efficient solution)
  873.  
  874.    I have to put some kind of middle ground between me and the toolbox;
  875.    even if I write it myself and call it MonstrousMacMemoryManager(), it
  876.    still does the same thing as the ANSI function malloc().  Why shouldn't
  877.    I save myself the work and borrow someone else's (gasp) ANSI code?
  878.  
  879. Ah, but then you have to live with the idiosyncharies of the
  880. code you borrow, right ? The PLUS side of Think C's malloc
  881. hanging on to the blocks is that the heap is not fragmented.
  882.  
  883. Cheers,
  884.  
  885. - -- 
  886.          Jon W{tte, Svartmangatan 18, S-111 29 Stockholm, Sweden
  887.  
  888. ### You have the Easy Access virus. This virus may cause strange sounds
  889. ### and weird keyboard behaviour when you press the shift key repeatedly.
  890.  
  891. +++++++++++++++++++++++++++
  892.  
  893. From: orpheus@reed.edu (P. Hawthorne)
  894. Date: 10 Jul 92 05:25:55 GMT
  895. Organization: Reed College, Portland, OR
  896.  
  897.  
  898.   k044477@hobbes.kzoo.edu (Jamie R. McCarthy) writes:
  899. . The best algorithm for what I'm doing requires that I allocate, as near
  900. . as I can figure, about 2000 20-byte blocks.  NewPtr() just won't cut it,
  901. . the Memory Manager isn't designed for that.
  902.  
  903.   You are right, of course. The Memory Manager is not so robust that it can
  904. be your only solution. However, the converse is also true. Malloc is no
  905. panacea either, especially in particularly strange terrain of a Macintosh
  906. application. Compromise is the answer.
  907.  
  908.   I don't know what sort of access patterns these blocks are subject to,
  909. but consider this approach:
  910.   Get your working room from NewPtr, which has no problem securing you a
  911. single large block, then hand out that memory out with your own malloc.
  912. If you need more working room, and you can't simply enlarge your original
  913. pointer, you could get another from NewPtr and so on.
  914.   It's handy, in that when you wanna release all of your malloc'd blocks,
  915. you can just nuke the block or blocks you got from the OS.
  916.  
  917.   A very, very, very interesting thread on c.s.n.p last month illustrated
  918. the wisdom of compromises of this sort. A migrant Mac programmer was
  919. lamenting the differences between Mac handle space and heap zones and the
  920. NeXT approach. I guess you can imagine the many justified responses, and I
  921. use the term loosely, the former Mac programmer was subjected to.
  922. Compromise saved the day, although the moist NeXT arch did its part too.
  923.  
  924.   The ultimate solution was practically the same as I give above. Get your
  925. high level chunks from the OS, and use it however you want. In other words,
  926. have your cake, and eat it too.
  927.  
  928.  
  929.  "Cross-platform development means never having to say you're sorry, 
  930.   just that you had to strike a compromise somewhere..."
  931.     Theus (orpheus@reed.edu)
  932.  
  933.  
  934. +++++++++++++++++++++++++++
  935.  
  936. From: k044477@hobbes.kzoo.edu (Jamie R. McCarthy)
  937. Organization: Kalamazoo College
  938. Date: Fri, 10 Jul 1992 14:18:29 GMT
  939.  
  940. d88-jwa@dront.nada.kth.se (Jon W{tte) writes:
  941. > k044477@hobbes.kzoo.edu (Jamie R. McCarthy) writes:
  942. >>Jon writes:
  943. >>>Hey, NOTHING RELEASED on the mac should call malloc().
  944. >>>... The mac is the mac is the mac,
  945. >>>it has a toolbox, and you'd better use it.
  946. >>
  947. >>The best algorithm for what I'm doing requires that I allocate, as near
  948. >>as I can figure, about 2000 20-byte blocks.  NewPtr() just won't cut it,
  949. >>the Memory Manager isn't designed for that.
  950. >
  951. >Ah, but you KNOW you allocate 20-byte blocks ?
  952.  
  953. Uh, er, well, no, I don't.  I should have been more precise:  about 2000,
  954. and about 20.  Actual block sizes range from about 4 to about 60, and the
  955. average is probably around 20.
  956.  
  957.  
  958. >[35 lines of "how to write a 20-byte-allocation heap" deleted]
  959. >Should be easy to implement...
  960.  
  961. Then Theus (orpheus@reed.edu) chimes in with:
  962. >  I don't know what sort of access patterns these blocks are subject to,
  963. >but consider this approach:
  964. >  Get your working room from NewPtr, which has no problem securing you a
  965. >single large block, then hand out that memory out with your own malloc.
  966. >If you need more working room, and you can't simply enlarge your original
  967. >pointer, you could get another from NewPtr and so on.
  968. >  It's handy, in that when you wanna release all of your malloc'd blocks,
  969. >you can just nuke the block or blocks you got from the OS.
  970.  
  971. Yeah, that's a great algorithm, Theus.  And yeah, Jon, that _would_ be
  972. easy to implement.  But it's already been done!
  973.  
  974. Both of you are basically suggesting writing what both Symantec and Tim
  975. have already written, to greater or lesser degrees of efficiency.
  976.  
  977. (I should add that my "access pattern" is very simple:  allocate
  978. everything all at once, use it, and dispose of it all at once.)
  979.  
  980.  
  981. >>Why shouldn't
  982. >>I save myself the work and borrow someone else's (gasp) ANSI code?
  983.  
  984. Jon again:
  985. >Ah, but then you have to live with the idiosyncharies of the
  986. >code you borrow, right ?
  987.  
  988. Yes.  I do.  I _like_ the idiosyncrasies of Tim's code.  If I liked the
  989. results of using Think's malloc(), I'd use it.  If I liked the results
  990. of just using NewPtr's, I'd do that.
  991.  
  992. >The PLUS side of Think C's malloc
  993. >hanging on to the blocks is that the heap is not fragmented.
  994.  
  995. That's like saying "the plus side of never disposing of anything is..."
  996. The _heap_'s not fragmented, but those 15K blocks are as fragmented as
  997. you can get (uncombined free space).
  998.  
  999.  
  1000. Come on, guys.  I love the Mac as much as you.  We all agree that the
  1001. Memory Manager needs a little help in this case.  But for some reason,
  1002. you think I should ignore the fact that someone else's code works for me
  1003. just fine.  I can't understand that.
  1004. - -- 
  1005.  Jamie McCarthy      Internet: k044477@kzoo.edu      AppleLink: j.mccarthy
  1006.  I suppose ya don't think I was run over by a streetcar!
  1007.  
  1008. +++++++++++++++++++++++++++
  1009.  
  1010. From: phils@chaos.cs.brandeis.edu (Phil Shapiro)
  1011. Date: 10 Jul 92 15:45:06 GMT
  1012. Organization: Symantec Corp.
  1013.  
  1014. >>>>> On Thu, 9 Jul 1992 16:34:08 GMT, k044477@hobbes.kzoo.edu (Jamie R. McCarthy) said:
  1015.  
  1016.  > I'm also working on a project that uses malloc(), and for my
  1017.  > purposes, Think's version was completely unacceptable.  From
  1018.  > looking at the source, I believe it's impossible for Think's malloc
  1019.  > to ever call DisposPtr unless you're freeing a block larger than
  1020.  > the 15K crossover size.
  1021.  
  1022. This is true. However, it's usually irrelevent as well, since the
  1023. free'd space can be used for other mallocs. Read on for more...
  1024.  
  1025.  > Consider calling malloc(98) 150 times.  This will return you 150
  1026.  > 98-byte blocks which, together with the overhead, take up one
  1027.  > entire 15000-byte block.  Now free() them all.  Now call
  1028.  > malloc(99).  Think's malloc(), since it doesn't accumulate free
  1029.  > space, will have to allocate an entirely new 15000-byte block.
  1030.  
  1031. Did you actually try this experiment out? I don't think you did,
  1032. because you would've found that THINK's malloc() *does* reclaim freed
  1033. space, and it *does* accumulate contiguous freed blocks.
  1034.  
  1035.  > Any non-application _must_not_ use Think's malloc().  My first try
  1036.  > at my screensaver left 15K non-relocatable driblets all over the
  1037.  > system heap until I figured out what was going on.  I didn't have
  1038.  > the luxury of trusting _ExitToShell to clean up for me.
  1039.  
  1040. This is a different scenario entirely. malloc() is not intended for
  1041. use in "real" Mac applications. It's useful if you have code which
  1042. already uses malloc, or if you need ANSI compatibility.
  1043.  
  1044. If you wanted to add an extra call to the malloc() source that frees
  1045. all of the blocks at once, it would be pretty simple. The zones are
  1046. organized in a ring using a pointer (located at zonestart + CROSSOVER
  1047. + 2), and each zone is a Mac Ptr. Once you've written this routine,
  1048. you could install it in an atexit() handler (or even in a patch to
  1049. _ExitToShell).
  1050.  
  1051.     -phil
  1052. - --
  1053.    Phil Shapiro                                   Software Engineer
  1054.    Language Products Group                     Symantec Corporation
  1055.            Internet: phils@cs.brandeis.edu
  1056.  
  1057. +++++++++++++++++++++++++++
  1058.  
  1059. From: k044477@hobbes.kzoo.edu (Jamie R. McCarthy)
  1060. Organization: Kalamazoo College
  1061. Date: Fri, 10 Jul 1992 16:07:23 GMT
  1062.  
  1063. phils@chaos.cs.brandeis.edu (Phil Shapiro) writes:
  1064. > k044477@hobbes.kzoo.edu (Jamie R. McCarthy) said:
  1065. > > Think's malloc(), since it doesn't accumulate free
  1066. > > space, will have to allocate an entirely new 15000-byte block.
  1067. >
  1068. >Did you actually try this experiment out? I don't think you did,
  1069. >because you would've found that THINK's malloc() *does* reclaim freed
  1070. >space, and it *does* accumulate contiguous freed blocks.
  1071.  
  1072. Whoops!  You're absolutely right, and I apologize.  The accumulation is
  1073. done in alloc(), not in free(), and I wasn't looking there (though I
  1074. must say, that's the logical place to do it).
  1075.  
  1076. >If you wanted to add an extra call to the malloc() source that frees
  1077. >all of the blocks at once, it would be pretty simple. The zones are
  1078. >organized in a ring using a pointer (located at zonestart + CROSSOVER
  1079. >+ 2), and each zone is a Mac Ptr.
  1080.  
  1081. Good information to know, thanks.  Maybe you mean CROSSOVER+4, tho'?
  1082. - -- 
  1083.  Jamie McCarthy      Internet: k044477@kzoo.edu      AppleLink: j.mccarthy
  1084.  I suppose ya don't think I was run over by a streetcar!
  1085.  
  1086. ---------------------------
  1087.  
  1088. From: dorner@pequod.cso.uiuc.edu (Steve Dorner)
  1089. Subject: windowKind usage
  1090. Organization: University of Illinois at Urbana-Champaign
  1091. Date: Thu, 9 Jul 1992 04:38:58 GMT
  1092.  
  1093.  
  1094. A certain screensaver which I do not care to name (it's part of a
  1095. commercial security package) does its thing by creating a window in
  1096. the frontmost application's heap, and giving the window a windowKind
  1097. of 9, or maybe 8, since they ran into a "compatibility problem" at 9.
  1098.  
  1099. Does this strike anyone else as incredibly hostile behavior?
  1100.  
  1101. Eudora looks at the window, says "Aha!  One of my own windows!" and goes
  1102. on to make very untrue assumptions about a number of things, causing
  1103. ugly things to happen.
  1104.  
  1105. If they're going to insist on putting a window in my windowlist in my
  1106. heap, I think they should use a windowKind < 8 (and not 2), so apps will
  1107. know to leave it alone.
  1108.  
  1109. Comments?
  1110. - -- 
  1111. Steve Dorner, Official Lame Duck, U of Illinois Computing Services Office
  1112. Internet: s-dorner@uiuc.edu  UUCP: uunet!uiucuxc!uiuc.edu!s-dorner
  1113.  
  1114. +++++++++++++++++++++++++++
  1115.  
  1116. From: leonardr@ccs.itd.umich.edu
  1117. Organization: Campus Computing Sites, University of Michigan-Ann Arbor
  1118. Date: Thu, 9 Jul 92 07:57:43 GMT
  1119.  
  1120. In article <Br3u8z.BCH@news.cso.uiuc.edu> s-dorner@uiuc.edu (Steve Dorner) writes:
  1121. >
  1122. >A certain screensaver which I do not care to name (it's part of a
  1123. >commercial security package) does its thing by creating a window in
  1124. >the frontmost application's heap, and giving the window a windowKind
  1125. >of 9, or maybe 8, since they ran into a "compatibility problem" at 9.
  1126. >
  1127. >Does this strike anyone else as incredibly hostile behavior?
  1128. >
  1129.     Putting a window into someone else's layer is an evil thing in its
  1130. own right, but using a POSITIVE windowKind is INSANE!!!  That is going to
  1131. break with Hypercard 2.x, MicroPhone II 4.0 and any application written
  1132. using MacApp 3l0 due to their "floating window" code.
  1133.  
  1134. >If they're going to insist on putting a window in my windowlist in my
  1135. >heap, I think they should use a windowKind < 8 (and not 2), so apps will
  1136. >know to leave it alone.
  1137. >
  1138.     Actually if they are going to continue to put things into application's
  1139. layers, then at least use negative IDs which are reserved for things like
  1140. DA's and system windows.
  1141.  
  1142.  
  1143. - -- 
  1144. - -----------------------------------------------------------------------
  1145. Leonard Rosenthol          Internet: leonardr@ccs.itd.umich.edu
  1146. Director of Advanced Technology   AppleLink: MACgician
  1147. Aladdin Systems, inc.          GEnie:     MACgician
  1148.  
  1149. +++++++++++++++++++++++++++
  1150.  
  1151. From: Quinn <quinn@cs.uwa.edu.au>
  1152. Organization: The University of Western Australia
  1153. Date: Fri, 10 Jul 1992 02:32:05 GMT
  1154.  
  1155. In article <Br3u8z.BCH@news.cso.uiuc.edu> Steve Dorner,
  1156. dorner@pequod.cso.uiuc.edu writes:
  1157. >A certain screensaver which I do not care to name (it's part of a
  1158. >commercial security package) does its thing by creating a window in
  1159. >the frontmost application's heap, and giving the window a windowKind
  1160. >of 9, or maybe 8, since they ran into a "compatibility problem" at 9.
  1161. >
  1162. >Does this strike anyone else as incredibly hostile behavior?
  1163.  
  1164. Yes.  I could easily imagine it breaking the application I'm currently 
  1165. in the process of designing.
  1166.  
  1167. >Eudora looks at the window, says "Aha!  One of my own windows!" and goes
  1168. >on to make very untrue assumptions about a number of things, causing
  1169. >ugly things to happen.
  1170. >
  1171. >If they're going to insist on putting a window in my windowlist in my
  1172. >heap, I think they should use a windowKind < 8 (and not 2), so apps will
  1173. >know to leave it alone.
  1174.  
  1175. Makes sense to me.  The semantics of a negative windowKind (ie DA) is
  1176. more defined than the semantics of a windowKind in [1, 3..7] (ie
  1177. reserved for future expansion).  More people are going to make
  1178. assumptions about the former than the latter. 
  1179.  
  1180. On another, related issue, does anyone know what Comms Toolbox tools do
  1181. with windowKind on their own windows?  The way I see it CTB tools act
  1182. like the evil screen dimmer described in that the can go merrily adding
  1183. windows into your application plane.  The official way of determining
  1184. whether it's a CTB window is by seeing if the refcon matches any of your
  1185. created CTB handles (CMHandle, TMHandle, FTHandle).  My question is
  1186. "If all my windows have a strange windowKind (eg 666 (-: ), can I be
  1187. sure that no CTB window will have that windowKind?"
  1188.  
  1189. Quinn "The Eskimo!"   <quinn@cs.uwa.edu.au>  "Real Coke, Diet .sig"
  1190. Department of Computer Science, The University of Western Australia
  1191.   -- Just some poor programmer trying to come to grips with CTB (-:
  1192.  
  1193. +++++++++++++++++++++++++++
  1194.  
  1195. From: mxmora@unix.SRI.COM (Matt Mora)
  1196. Date: 10 Jul 92 16:23:38 GMT
  1197. Organization: SRI International, Menlo Park, California
  1198.  
  1199. In article <Br3u8z.BCH@news.cso.uiuc.edu> s-dorner@uiuc.edu (Steve Dorner) writes:
  1200.  
  1201. >If they're going to insist on putting a window in my windowlist in my
  1202. >heap, I think they should use a windowKind < 8 (and not 2), so apps will
  1203. >know to leave it alone.
  1204.  
  1205. >Comments?
  1206.  
  1207. Yeah, TRUST NO ONE!
  1208.  
  1209. I usually tag my windows with my signature to make sure the window is mine.
  1210. Call me paranoid but its the only way for sure that I know its my window
  1211. and not someone elses. I usually have a bunch of fields attached to my windows
  1212. anyway so whats a few more bytes just to be sure.
  1213.  
  1214. Matt
  1215.  
  1216.  
  1217.  
  1218. - -- 
  1219. ___________________________________________________________
  1220. Matthew Mora                |   my Mac  Matt_Mora@sri.com
  1221. SRI International           |  my unix  mxmora@unix.sri.com
  1222. ___________________________________________________________
  1223.  
  1224. ---------------------------
  1225.  
  1226. End of C.S.M.P. Digest
  1227. **********************
  1228.